﻿using System;
using System.Linq;

namespace DeepEarth.Core
{
    [AttributeUsage(AttributeTargets.Class)]
    public class AtomicEntityAttribute : Attribute
    {
        public AtomicEntityAttribute()
        {
            GroupItems = true;
        }

        public AtomicEntityAttribute(bool groupItems)
        {
            GroupItems = groupItems;
        }

        public bool GroupItems { get; set; }

        public static bool IsAtomic(object o)
        {
            System.Reflection.MemberInfo info = o.GetType();
            var aea = info.GetCustomAttributes(true).OfType<AtomicEntityAttribute>().FirstOrDefault();

            return (aea != null && aea.GroupItems);
        }
    }
}